struct LightSourceParameters {
	vec4 ambient; 
	vec4 diffuse; 
	vec4 specular; 
	vec4 position; 
	vec4 halfVector; 
	vec3 spotDirection; 
	float spotExponent; 
	float spotCutoff; // (range: [0.0,90.0], 180.0)
	float spotCosCutoff; // (range: [1.0,0.0],-1.0)
	float constantAttenuation; 
	float linearAttenuation; 
	float quadraticAttenuation;	
};

struct LightModelParameters {
	vec4 ambient; 
};

struct Material {
		vec4 emission;   
		vec4 ambient;    
		vec4 diffuse;    
		vec4 specular;   
		float shininess; 
	};

LightSourceParameters LightSource[1];
LightModelParameters LightModel;
Material u_material;

uniform mat4 u_mvp_matrix;
uniform mat4 u_mv_matrix;
uniform mat3 u_normal_matrix;

attribute vec3 a_normal;
attribute vec4 a_vertex_coord;
attribute vec2 a_uv_coord;

varying vec4 v_color;
varying vec2 v_texCoord;
	
void main() {
	v_texCoord = a_uv_coord;
	
	u_material.ambient = vec4(0.3, 0.3, 0.3, 1.);
	u_material.diffuse = vec4(0.5, 0.5, 0.5, 1.);
	
	LightSource[0].position = u_mv_matrix * vec4(1.0, 0.0, 1.0, 0.0);
	LightSource[0].position = normalize(vec4(0.0, 0.0, 1.0, 0.0));
	LightSource[0].diffuse = vec4(0.6, 0.6, 0.6, 1.0);
	LightSource[0].ambient = vec4(0.6, 0.6, 0.6, 1.0);

	vec3 normal, lightDir;
	vec4 diffuse, ambient;
	float NdotL;
	
	/* first transform the normal into eye space and normalize the result */
	normal = normalize(u_normal_matrix * a_normal);
	
	/* now normalize the light's direction. Note that according to the
	OpenGL specification, the light is stored in eye space. Also since 
	we're talking about a directional light, the position field is actually 
	direction */
	lightDir = normalize(vec3(LightSource[0].position));
	
	/* compute the cos of the angle between the normal and lights direction. 
	The light is directional so the direction is constant for every vertex.
	Since these two are normalized the cosine is the dot product. We also 
	need to clamp the result to the [0,1] range. */
	NdotL = max(dot(normal, lightDir), 0.0);
	
	/* Compute the diffuse term */
	diffuse = u_material.diffuse * LightSource[0].diffuse;
	ambient = u_material.ambient * LightSource[0].ambient;
	
	v_color =  NdotL * diffuse + ambient;

	gl_Position = u_mvp_matrix * a_vertex_coord;
}